
<template>
  <div class="message-box__container" v-if="showCopyPopup">
    <copyPasswordDialog
      :showPopup="showCopyPopup"
      :orderInfo="payResult"
      :price="finalPrice"
      :isCheckOrderState="isCheckOrderState"
      @changeShowCopy="changeShowCopyFun"
      @checkOrderState="checkOrderState"
    ></copyPasswordDialog>
  </div>
</template>

<script>
import copyPasswordDialog from "./copyPasswordDialog.vue";
import { PayBackHandler } from "../../strategy/pay-back-handler";

export default {
  props: {
    payResult: {
      type: Object,
      default: () => {},
    },
    finalPrice: {
      type: Number || String,
      default: 0,
    },
  },
  data() {
    return {
      showCopyPopup: false,
      isCheckOrderState: true,
    };
  },
  components: {
    copyPasswordDialog,
  },
  methods: {
    hideBox() {
      this.showCopyPopup = false;
    },
    showBox() {
      this.showCopyPopup = true;
    },
    changeShowCopyFun(val) {
      this.showCopyPopup = val;
    },
    /**
     * 根据缓存校验订单是否支付，然后进行相关跳转
     */
    checkOrderState(failCallBack = () => {}) {
      const { paySuccessUrl, payFailUrl } = this.payResult;

      if (this.payResult) {
        new PayBackHandler(paySuccessUrl, payFailUrl, this.payResult).perform(
          failCallBack
        );
      }
    },
  },
};
</script>